package com.gy.bearhelps.util;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

/**
 * Created by 高岳 on 2016/8/3.
 * Describe:获取手机信息
 */
public class DeviceInfo {
	private static String MAC = null;
	private static String IMEI = null;

	/**
	 * 获取手机的mac地址
	 * @param context
	 * @return
	 */
	public static String getMac(Context context) {
		if (TextUtils.isEmpty(MAC)) {			
			WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
			WifiInfo info = wifi.getConnectionInfo();
			MAC = info.getMacAddress();
		}
		return MAC;

	}

	/**
	 * 获取手机IMEI号
	 * @param context
	 * 如果获取手机的IMEI失败，则获取经过MD5验证的mac信息
	 */
	public static String getIMEI(Context context) {
		if (TextUtils.isEmpty(IMEI)) {			
			TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
			IMEI = tm.getDeviceId();
//			if (TextUtils.isEmpty(IMEI)) {
//				IMEI = Utils.MD5(getMac(context));
//			}
		}
		return IMEI;
	}
}
